package security.Roles;

import java.util.Vector;

public class VectorPrivilege extends Privilege {

private String privilegeName;
	
	public VectorPrivilege(String privilegeName) {
		this.privilegeName = privilegeName;
	}
	
	// scope: package.....package.class.method()
	private String scope;
	
	// params key => value
	private String[] params;
	
	// isallowed
	private boolean isAllowed;

	public boolean isAllowed(Object[] identifier) {
		return true;
	}

	public void setAllowed(boolean isAllowed) {
		this.isAllowed = isAllowed;
	}

	public String[] getParams() {
		return params;
	}

	public void setParams(String[] params) {
		this.params = params;
	}

	public String getPrivilegeName() {
		return privilegeName;
	}

	public void setPrivilegeName(String privilegeName) {
		this.privilegeName = privilegeName;
	}

	public String getScope() {
		return scope;
	}

	public void setScope(String scope) {
		this.scope = scope;
	}
	
	private static Vector<Privilege> allPrivileges = new Vector<Privilege>();
	
	public static boolean addPrivilege(Privilege p) {		
		return allPrivileges.add(p);
	}
	public static boolean savePrivilege(Privilege p) {
		// not needed
		return true;
	}
	public static boolean delPrivilege(Privilege p) {
		return allPrivileges.remove(p);
	}
	public static Vector<Privilege> getPrivileges() {
		return allPrivileges;
	}
	public static Privilege getPrivilegeByName(String privilegeName) {
		for (int i=0;i<allPrivileges.size();i++){ 
			if (allPrivileges.get(i).getPrivilegeName().equals(privilegeName)) {
				return allPrivileges.get(i);
			}
		}
		return null;
	}		
	
}
